package com.tianxiao.faas.application.web.corner;

import com.tianxiao.faas.api.param.corner.AiOrderParam;
import com.tianxiao.faas.application.aop.AuthenticationContextHolder;
import com.tianxiao.faas.biz.service.corner.AiService;
import com.tianxiao.faas.common.access.Access;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.annotation.Resource;

@RestController
@RequestMapping("/app/ai")
public class AiController {

    @Resource
    private AiService aiService;

    @RequestMapping(value = "/order", produces = "text/event-stream")
    @Access
    public SseEmitter order(@RequestBody AiOrderParam aiOrderParam) {
        Long userId = AuthenticationContextHolder.currentContext().getUserId();
        SseEmitter emitter = aiService.order(aiOrderParam, userId);
        return emitter;
    }


}
